package com.demo.apparel.controller.uniapp;

import com.demo.apparel.common.Result;
import com.demo.apparel.dto.PageRequestDTO;
import com.demo.apparel.dto.uniapp.WxFeedbackDTO;
import com.demo.apparel.dto.uniapp.WxFeedbackSubmitDTO;
import com.demo.apparel.service.uniapp.WxFeedbackService;
import com.demo.apparel.vo.PageVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/wx/feedback")
@Tag(name = "反馈接口", description = "用户信息反馈")
public class WxFeedbackController {

    @Autowired
    private WxFeedbackService wxFeedbackService;

    /**
     *
     * @param files
     * @param userId
     * @return
     */
    @PostMapping(value = "/image", produces = "application/json;charset=UTF-8")
    @Operation(summary = "上传反馈图片（支持多张），返回每张图片的URL和ID")
    public Result<List<Map<String, String>>> uploadImages(@RequestParam("files") List<MultipartFile> files,
                                                          @RequestAttribute("userId") String userId) {
        List<Map<String, String>> result = wxFeedbackService.feedbackImageAndSave(files, userId);
        return Result.successes(result, "success");
    }

    /**
     *
     * @param dto
     * @param userId
     * @return
     */
    @PostMapping("/submit")
    @Operation(summary = "提交反馈信息")
    public Result<Void> submitFeedback(@RequestBody WxFeedbackSubmitDTO dto,
                                       @RequestAttribute("userId") String userId) {

        wxFeedbackService.submitFeedback(dto, userId);
        return Result.success(null);
    }

    /**
     *
     * @param query
     * @return
     */
    @PostMapping("/list")
    @Operation(summary = "获取自己提交反馈的列表")
    public Result<PageVO<WxFeedbackDTO>> getMyFeedbackList(@RequestBody PageRequestDTO query,
                                                           @RequestAttribute("userId") String userId) {

        PageVO<WxFeedbackDTO> pageVO = wxFeedbackService.getUserFeedbackPage(
                 userId,query.getPageNum(), query.getPageSize()
        );
        return Result.success(pageVO);
    }

    /**
     *
     * @param id
     * @return
     */
    @GetMapping("/detail")
    @Operation(summary = "查看某个反馈的详情以及管理员回复")
    public Result<WxFeedbackDTO> getFeedbackDetail(@RequestParam String id) {
        WxFeedbackDTO dto = wxFeedbackService.getFeedbackDetail(id);
        return Result.success(dto);
    }

}
